﻿using GalaSoft.MvvmLight;
using Northwind.Interfaces.Data.Model;
using GalaSoft.MvvmLight.Messaging;
using Northwind.ViewModel.Messeges;
using System;

namespace Northwind.ViewModel
{
    public class OrderDetailsViewModel : ToolViewModel
    {
        private readonly IOrderModel _order;                

        public OrderDetailsViewModel(IOrderModel order)
        {            
            _order = order;
            Name = Strings.OrderInformationDisplayName;
            ToolTitle = _order.OrderID.ToString();
            Messenger.Default.Register<OrderCancelled>(this, CloseTool);
        }

        public IOrderModel Order { get { return _order;}}

        private void CloseTool(OrderCancelled orderCancelledMessage)
        {
            if (orderCancelledMessage.CancelledOrder.OrderID == this.Order.OrderID)
            {
                OnRequestClose();
            }
        }
    }
}